package com.mf.ergate.controller.bo.pt;

import com.mf.ergate.api.bo.pt.PtOrderDeliveryRemoteService;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderDeliveryCreateDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderDeliveryDeleteDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderDeliveryQueryDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderDeliveryUpdateDto;
import com.mf.ergate.api.bo.pt.model.vo.PtOrderDeliveryVo;
import com.mf.ergate.common.utils.MfBeanUtils;
import com.mf.ergate.domain.model.bo.pt.PtOrderDeliveryEntity;
import com.mf.ergate.service.bo.pt.PtOrderDeliveryService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import com.mf.framework.common.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 跑腿订单配送Controller
 * User: zhaoming
 * DateTime: 2019-01-28
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class PtOrderDeliveryController implements PtOrderDeliveryRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PtOrderDeliveryService ptOrderDeliveryService;

    /**
     * 新增
     * @param ptOrderDeliveryCreateDto 跑腿订单配送新增Dto
     * @return 跑腿订单配送
     */
    public Result<PtOrderDeliveryVo> insert(@RequestBody PtOrderDeliveryCreateDto ptOrderDeliveryCreateDto) {
        PtOrderDeliveryEntity ptOrderDeliveryEntity = MfBeanUtils.copyObject(ptOrderDeliveryCreateDto, PtOrderDeliveryEntity.class);
        ptOrderDeliveryEntity = ptOrderDeliveryService.insert(ptOrderDeliveryEntity);
        PtOrderDeliveryVo ptOrderDeliveryVo = MfBeanUtils.copyObject(ptOrderDeliveryEntity, PtOrderDeliveryVo.class);
        return new Result<>(ptOrderDeliveryVo);
    }

    /**
     * 根据唯一编号更新
     * @param ptOrderDeliveryUpdateDto 跑腿订单配送更新Dto
     * @return 执行结果
     */
    public Result<Boolean> updateByUniqueNo(@RequestBody PtOrderDeliveryUpdateDto ptOrderDeliveryUpdateDto) {
        PtOrderDeliveryEntity ptOrderDeliveryEntity = MfBeanUtils.copyObject(ptOrderDeliveryUpdateDto, PtOrderDeliveryEntity.class);
        Boolean flag = ptOrderDeliveryService.updateByUniqueNo(ptOrderDeliveryEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param ptOrderDeliveryDeleteDto 跑腿订单配送删除Dto
     * @return 结果集
     */
    public Result<Boolean> deleteByUniqueNo(@RequestBody PtOrderDeliveryDeleteDto ptOrderDeliveryDeleteDto){
        PtOrderDeliveryEntity ptOrderDeliveryEntity = MfBeanUtils.copyObject(ptOrderDeliveryDeleteDto, PtOrderDeliveryEntity.class);
        Boolean flag = ptOrderDeliveryService.deleteByUniqueNo(ptOrderDeliveryEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 唯一编号
     * @return 跑腿订单配送
     */
    public Result<PtOrderDeliveryVo> selectByUniqueNo(@RequestBody String uniqueNo) {
        PtOrderDeliveryEntity ptOrderDeliveryEntity = ptOrderDeliveryService.selectByUniqueNo(uniqueNo);
        PtOrderDeliveryVo ptOrderDeliveryVo = MfBeanUtils.copyObject(ptOrderDeliveryEntity, PtOrderDeliveryVo.class);
        return new Result<>(ptOrderDeliveryVo);
    }

    /**
     * 根据条件查询
     * @param ptOrderDeliveryQueryDto 跑腿订单配送查询Dto
     * @return 跑腿订单配送列表
     */
    public Result<List<PtOrderDeliveryVo>> selectByCondition(@RequestBody PtOrderDeliveryQueryDto ptOrderDeliveryQueryDto) {
        List<PtOrderDeliveryEntity> ptOrderDeliveryEntities = ptOrderDeliveryService.selectByCondition(ptOrderDeliveryQueryDto);
        List<PtOrderDeliveryVo> ptOrderDeliveryVos = MfBeanUtils.copyList(ptOrderDeliveryEntities, PtOrderDeliveryVo.class);
        return new Result<>(ptOrderDeliveryVos);
    }

    /**
     * 根据条件查询数量
     * @param ptOrderDeliveryQueryDto 跑腿订单配送查询Dto
     * @return 数量
     */
    public Result<Integer> selectCount(@RequestBody PtOrderDeliveryQueryDto ptOrderDeliveryQueryDto) {
        return new Result<>(ptOrderDeliveryService.selectCount(ptOrderDeliveryQueryDto));
    }

    /**
     * 根据条件分页查询
     * @param remotePage 远程分页对象
     * @return 跑腿订单配送分页列表
     */
    public Result<Page<PtOrderDeliveryVo>> selectPage(@RequestBody RemotePage<PtOrderDeliveryQueryDto> remotePage){
        Page<PtOrderDeliveryEntity> ptOrderDeliveryEntityPage = ptOrderDeliveryService.selectPage(remotePage.getPage(), remotePage.getObj());
        Page<PtOrderDeliveryVo> page = MfBeanUtils.copyPage(ptOrderDeliveryEntityPage, PtOrderDeliveryVo.class);
        return new Result<>(page);
    }

}